package cn.pegasus.teamwork.pegasus.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.pegasus.teamwork.pegasus.entity.BussServiceProject;
import cn.pegasus.teamwork.pegasus.entity.BussWasherFunddetails;
import cn.pegasus.teamwork.pegasus.mapper.BussServiceProjectMapper;
import cn.pegasus.teamwork.pegasus.service.BussServiceProjectService;
import cn.pegasus.teamwork.pegasus.service.BussUcenterAreaService;
import cn.pegasus.teamwork.util.IDGenerator;
import cn.iyizhan.teamwork.base.service.impl.BaseServiceImpl;
import cn.iyizhan.teamwork.base.util.PageHelper;
import cn.iyizhan.teamwork.base.util.PageObject;

/**
 * @author ryan.bian
 * @version 
 */
@Service("bussServiceProjectService")
public class BussServiceProjectServiceImpl extends BaseServiceImpl<BussServiceProject, BussServiceProjectMapper> implements BussServiceProjectService {
	// 注入当前dao对象
	@Autowired
	private BussUcenterAreaService ucenterAreaService;
    @Autowired
    private BussServiceProjectMapper bussServiceProjectMapper;

    public BussServiceProjectServiceImpl() {
        setMapperClass(BussServiceProjectMapper.class, BussServiceProject.class);
    }
    
	@Override
	public PageObject<BussServiceProject> PageList(Map<String, Object> map) {
		int totalData = bussServiceProjectMapper.getTotal(map);
        PageHelper pageHelper = new PageHelper(totalData, map);
        List<BussServiceProject> list = bussServiceProjectMapper.findListByPage(pageHelper.getMap());
        for(BussServiceProject p : list){
        	if(p.getAreaId()!=null){
        		String name = ucenterAreaService.getAreaName(p.getAreaId());
        		p.setAreaName(name);
        	}
        }
        PageObject<BussServiceProject> pageObject = pageHelper.getPageObject();
        pageObject.setDataList(list);
		return pageObject;
	}

	@Override
	public BussServiceProject findProjectInfo(Long id) {
		BussServiceProject p = new BussServiceProject();
		p.setId(id);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", id);
		return bussServiceProjectMapper.findListByPage(map).get(0);
	}

	@Override
	public void addProject(Long id,BussServiceProject project) {
		project.setCreateTime(new Date());
		project.setUpdateTime(new Date());
		project.setCreateUserBy(id);
		project.setUpdateUserBy(id);
		project.setClassicStatus(0);
		project.setProjectCode(IDGenerator.get("18PR"));
		bussServiceProjectMapper.insertByEntity(project);
	}

	@Override
	public void updateProject(Long id,BussServiceProject project) {
		project.setUpdateTime(new Date());
		project.setUpdateUserBy(id);
		bussServiceProjectMapper.updateByEntity(project);
	}

	@Override
	public void delete(Long id, Long projectId) {
		BussServiceProject project = new BussServiceProject();
		project.setUpdateTime(new Date());
		project.setUpdateUserBy(id);
		project.setId(projectId);
		project.setClassicStatus(1);
		bussServiceProjectMapper.updateByEntity(project);
	}

	@Override
	public String findProjectName(Long id) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", id);
		return bussServiceProjectMapper.findProjectName(map);
	}
    
 
}
